/**
 * \file sphere.hpp
 * 
 * \section COPYRIGHT
 *
 * Basis: A 3D Mathematics Library
 *
 * ---------------------------------------------------------------------
 *
 * Copyright (c) 2010, Don Olmstead
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  1. Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *
 *  3. Neither the name of organization nor the names of its contributors may be
 *     used to endorse or promote products derived from this software without
 *     specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef BASIS_SPHERE_HPP_INCLUDED
#define BASIS_SPHERE_HPP_INCLUDED

#include <basis/vector3.hpp>

namespace basis
{
	/**
	 * Defines a sphere.
	 *
	 * \tparam Real A real number type.
	 * \tparam InstructionSet The SIMD instruction set to use.
	 *
	 * \author Don Olmstead
	 * \version 0.1
	 */
	template <typename Real, typename InstructionSet = simd::none>
	class sphere
	{

		//------------------------------------------------------------
		// Member types
		//------------------------------------------------------------

		public:

			/// Value of a real number
			typedef Real value_type;
			/// Reference to a real number
			typedef Real& reference;
			/// Value of a vector3
			typedef vector3<Real, InstructionSet> vector_type;
			/// Reference to a vector3
			typedef vector3<Real, InstructionSet>& vector_reference;
			/// Constant reference to a vector3
			typedef const vector3<Real, InstructionSet>& const_vector_reference;

		//------------------------------------------------------------
		// Construction/Destruction
		//------------------------------------------------------------

		public:

			/**
			 * Creates an instance of the sphere class.
			 *
			 * Uninitialized to speed creation.
			 */
			sphere()
			{ }

			/**
			 * Destroys an instance of the sphere class.
			 */
			~sphere()
			{ }

			/**
			 * Initializes an instance of the sphere class.
			 *
			 * \param center The center point of the sphere.
			 * \param radius The radius of the sphere.
			 */
			sphere(const_vector_reference center, value_type radius)
				: _center(center)
				, _radius(radius)
			{ }

			/**
			 * Initializes an instance of the sphere class.
			 *
			 * Creates a copy of the given instance.
			 *
			 * \param copy The sphere to copy.
			 */
			sphere(const sphere& copy)
				: _center(copy._center)
				, _radius(copy._radius)
			{ }

			/**
			 * Assignment operator for the sphere class.
			 *
			 * Copies the values from the inputed sphere.
			 *
			 * \param copy The sphere to copy.
			 * \returns A copy of the inputed sphere.
			 */
			inline sphere& operator= (const sphere& copy)
			{
				_center = copy._center;
				_radius = copy._radius;

				return *this;
			}

		//------------------------------------------------------------
		// Comparison operators
		//------------------------------------------------------------

		public:

			/**
			 * Determines whether two spheres are equal.
			 *
			 * \param compare The sphere to compare with.
			 * \returns \b true if the instances are equal; \b false otherwise.
			 */
			inline bool operator== (const sphere& compare) const
			{
				return (_radius == compare._radius) && (_center == compare._center);
			}

			/**
			 * Determines whether two spheres are not equal.
			 *
			 * \param compare The sphere to compare with.
			 * \returns \b true if the instances are not equal; \b false otherwise.
			 */
			inline bool operator!= (const sphere& compare) const
			{
				return (_radius != compare._radius) && (_center != compare._center);
			}

		//------------------------------------------------------------
		// Accessors
		//------------------------------------------------------------

		public:

			/**
			 * Retrieves the center point of the sphere.
			 *
			 * \returns The center point of the sphere.
			 */
			inline const_vector_reference center() const
			{
				return _center;
			}

			/**
			 * Retrieves the center point of the sphere.
			 *
			 * \returns The center point of the sphere.
			 */
			inline vector_reference center()
			{
				return _center;
			}

			/**
			 * Retrieves the radius of the sphere.
			 *
			 * \returns The radius of the sphere.
			 */
			inline value_type radius() const
			{
				return _radius;
			}

			/**
			 * Retrieves the radius of the sphere.
			 *
			 * \returns The radius of the sphere.
			 */
			inline reference radius()
			{
				return _radius;
			}

		 private:

			 /// The center point of the sphere.
			 vector_type _center;
			 /// The radius of the sphere.
			 value_type _radius;

	} ; // end class sphere

} // end namespace basis

#endif // end BASIS_SPHERE_HPP_INCLUDED
